package com.example.cstr.entity;

import com.fasterxml.jackson.annotation.JsonView;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

@Data
public class Message<T>{
    public interface UnionSimpleView{};

    //状态码
    @ApiModelProperty(value="请求结果")
    @JsonView(UnionSimpleView.class)
    private boolean result;

    //错误成功信息
    @ApiModelProperty(value="补充信息")
    @JsonView(UnionSimpleView.class)
    private String msg;

    //包含的数据
    @ApiModelProperty(value="包含数据")
    @JsonView(UnionSimpleView.class)
    private T obj;

    private Message(boolean result, String msg){
        this.result=result;
        this.msg=msg;
    }

    public static<T> Message<T> success(String str){
        return new Message<T>(true,str==null?"操作成功":str);
    }

    public static<T> Message<T> fail(String str){
        return new Message<T>(false,str==null?"操作失败":str);
    }

    //添加的数据
    public Message add(T obj){
        this.setObj(obj);
        return this;
    }

}
